// 引入模块
const fs = require('fs'),
  path = require('path'),
  express = require('express'),
  qs = require('querystring'),
  axios = require('axios')

// 创建服务器
const app = express()

// 设置请求头, 解决跨域问题
app.all('*', (request, response, next) => {
  response.header('Access-Control-Allow-Origin', '*')
  response.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS');
  response.header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
  next()
})

// 处理post请求传入的数据
app.use(express.json())
// 处理get请求传入的数据
app.use(express.urlencoded())

// 响应静态资源
app.use(express.static(path.join(__dirname, './dist')))

// 接口
app.get('/banner', async (req, res) => {
  // 申请banner数据
  // try {
  //   const res1 = await axios.get('http://121.89.213.194:5001/banner')
  //   console.log('进入banner接口')
    res.send({
      code: 200,
      msg: '成功',
      data: 'res1.data.banners'
    })
  // } catch (e) {
  //   console.log(e)
  // }


})

// 监听端口
const port = 25041
app.listen(port, () => console.log('app is running at http://localhost:' + port));
